using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.CompilerServices;
using TuyennvLibrary.SqlClient;
namespace TuyennvLibrary.ServerApi.Views
{
    public class ViewApplicationDevices
    {
        public int id { get; set; }
        public string appid { get; set; }
        public string deviceid { get; set; }
        public string gcmid { get; set; }
        public int platform { get; set; }
        public DateTime createdate { get; set; }

        public static string COLUMN_ID = "id";
        public static string COLUMN_APPID = "appid";
        public static string COLUMN_DEVICEID = "deviceid";
        public static string COLUMN_GCMID = "gcmid";
        public static string COLUMN_PLATFORM = "platform";
        public static string COLUMN_CREATEDATE = "createdate";

        public static string TableName = "ViewApplicationDevices";

        public ViewApplicationDevices()
        {
            this.id = 0;
            this.appid = string.Empty;
            this.deviceid = string.Empty;
            this.gcmid = string.Empty;
            this.platform = 0;

        }
    }
    public class ViewApplicationDevicesModel : BaseModel<ViewApplicationDevices>
    {
        public ViewApplicationDevicesModel()
        {
            table = ViewApplicationDevices.TableName;
        }
        public ViewApplicationDevices GetBy(DataRow dr)
        {
            ViewApplicationDevices obj = new ViewApplicationDevices();
            obj.id = (dr["id"] is DBNull) ? 0 : int.Parse(dr["id"].ToString());
            obj.appid = (dr["appid"] is DBNull) ? string.Empty : dr["appid"].ToString();
            obj.deviceid = (dr["deviceid"] is DBNull) ? string.Empty : dr["deviceid"].ToString();
            obj.gcmid = (dr["gcmid"] is DBNull) ? string.Empty : dr["gcmid"].ToString();
            obj.createdate = (dr["createdate"] is DBNull) ? DateTime.Now : DateTime.Parse(dr["createdate"].ToString());
            return obj;
        }
        public List<ViewApplicationDevices> GetListBy(DataTable dt)
        {
            List<ViewApplicationDevices> list = new List<ViewApplicationDevices>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ViewApplicationDevices obj = GetBy(dr);
                    list.Add(obj);
                }
            }
            return list;
        }
        public DataTable GetListAll()
        {
            try
            {
                DataTable dt = DB.SelectDataTable(table);
                return dt;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public ViewApplicationDevices GetBy(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ViewApplicationDevices obj = GetBy(dr);

                    return obj;
                }
            }
            return new ViewApplicationDevices();
        }
        public ViewApplicationDevices GetByID(int id)
        {
            try
            {
                DataTable dt = DB.SelectDataTable(null, table, new SqlParameter[] { 
					new SqlParameter("id",id),
															
                }, null);
                return GetBy(dt);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public ViewApplicationDevices GetByAppidDeviceid(string appid, string deviceid)
        {
            try
            {
                DataTable dt = DB.SelectDataTable(null, table, new SqlParameter[] { 
					new SqlParameter("appid",appid),
					new SqlParameter("deviceid",deviceid),									
                }, null);
                return GetBy(dt);
            }
            catch (Exception)
            {

                throw;
            }
        }
        
        
    }
}
